package com.eastfair.projectcore.enumeration;

import com.eastfair.annotation.base.BaseEnum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * <p>
 * 实体注释中生成的类型枚举
 * 前端菜单（之所以分开是因为避免指定上级菜单出错）
 * </p>
 *
 * @author ligang
 * @date 2021-10-28
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "AppMenuMenuTypeEnum", description = "菜单类型 #{catalog:目录;menu:菜单;button:按钮-枚举")
public enum AppMenuMenuTypeEnum implements BaseEnum {

    /**
     * CATALOG="目录"
     */
    CATALOG("目录"),
    /**
     * MENU="菜单"
     */
    MENU("菜单"),
    /**
     * BUTTON="按钮"
     */
    BUTTON("按钮"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static AppMenuMenuTypeEnum match(String val, AppMenuMenuTypeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static AppMenuMenuTypeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(AppMenuMenuTypeEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "CATALOG,MENU,BUTTON", example = "CATALOG")
    public String getCode() {
        return this.name();
    }

}
